<!--资产列表 -->
<template>
    <div class="page assetsList-page" data-page="assetsListForMore" style="z-index: 2;">
        <div class="link-page-nav">
            <a href="#" class="link" @click="$root.backToTab()">
                <i class="iconfont icon-zuo"></i>
            </a>
        </div>
        <div class="link-page-search">
        	<span class="tt">消防资产</span>
            <a class="link popover-open" data-popover="#assets_menu">
                <i class="iconfont icon-APPicon_shaixuan1
" id="active" style="font-size:24px"></i>
            </a>
        </div>
        <div data-infinite-distance="50" class="page-content pdbottom120">
            <ul id="org-assets-info-list" style="height:100%"></ul> 
        </div>
        <div class="more-task-btn"   @click="scanning">
            <i class="iconfont icon-weibiaoti--2"></i>
        </div>
        <div class="popover select-option-con" id="assets_menu">
          <div class="popover-angle"></div>
          <div class="popover-inner">
            <div class="list">
              <ul>
                <li><a href="" class="list-button item-link popover-close" id="select_org">选择单位</a></li>
                <li><a href="" class="list-button item-link popover-close removeScreen select-active" @click="removeScreen" >清&nbsp&nbsp&nbsp&nbsp&nbsp空</a></li>
              </ul>
            </div>
            </div>
        </div>
    </div>
</template>
<script>
    return {
        mounted() {
            var self = this;
            var app = self.$app;
        },
        data: function () {
            return {
                pageName:"assetsListForMore", 
                allowInfinite: true,
                currentOrgId: 0,
                selectOptionOrg : 0,
                selectContent:'',
            }
        },
        methods: {
            //原生扫一扫
            scanning:function(){
                native.scanQrCode();
            },
            //获取列表数据
            getAssetsInfo:function(){
                var self = this;
                var $ = self.$;
                //筛选按钮有值变色
                if(jQuery("#select_org")[0].innerText != "选择单位"){
                    jQuery("#active").addClass("select-active");
                }else{
                    jQuery("#active").removeClass("select-active");
                }
                $("#org-assets-info-list").empty();
                Dao.getOrgAssetsInfoForApp({
                    userName:userInfor.accountName,
                    deviceId:appKeyObj.deviceId,
                    orgIds:self.currentOrgId,
                    name:self.selectContent,
                },function(data) {
                	if (data && data.length > 0){
	                    for(var i=0;i<data.length;i++){
	                        $("#org-assets-info-list").append(`
	                        <li class="assets-info-tital" id="orgId_`+data[i].orgId+`">
	                            <div class="assets-type-name">`+data[i].orgName+`的资产</div>
	                            <div class="assets-line">
	                            	<div class="assets-item">
	                            		<p class="assets-item-title">消防系统</p>
	                            		<p class="assets-item-num">`+data[i].fireSystem+`<span span class="assets-item-unit">种</span</p>
	                            	</div>
	                            	<div class="assets-item assets-need-maintain">
		                        		<p class="assets-item-title">资产类别</p>
		                        		<p class="assets-item-num">`+data[i].type+`<span span class="assets-item-unit">个</span</p>
	                        		</div>
	                        		<div class="assets-item assets-need-maintain" style="width:22%">
		                        		<p class="assets-item-title">资产总数</p>
		                        		<p class="assets-item-num assets-item-color">`+data[i].total+`<span span class="assets-item-unit">个</span</p>
	                    			</div>
	                        		<div class="assets-item assets-need-maintain" style="width:22%">
		                        		<p class="assets-item-title">过期资产数</p>
		                        		<p class="assets-item-num">`+data[i].expireCount+`<span class="assets-item-unit">个</span</p>
	                    			</div>
	                            </div>
	                        </li>
                            `);
                              // // 资产子级
                              jQuery(".showDom").off("click").on("click",{'data':data[i]},function(e) {
                                e.preventDefault();
                                var data = e.data.data;
                                app.router.navigate("/assetsNextChild/"+self.currentOrgId+'/'+data.fbsId+'/'+data.type+'/');
                            });
	                        //资产列表
	                        jQuery("#orgId_"+data[i].orgId).off("click").on("click",{'data':data[i]},function(e) {
                                IfJzwFlag=true
                                var data = e.data.data;
                                app.router.navigate("/assetsListForSingle/"+data.orgId+'/'+ 0 +'/'+ 0 +'/');
	                        });
	                    }
	                }else{//没有数据
	                	 $("#org-assets-info-list").empty().append(`<div class="no-data-img"><img src="`+listNoDataPic()+`"/></div>`);
	                }
                });
            },
            backToTab: function() {
                app.methods.backToTab();
            },
            removeScreen:function(){
                var self = this;
                if (userInfor.isMuilUnitUser == 1){//多
                    if (single_Orgid == "") {
                      self.currentOrgId=userInfor.organizationIds;
                    } else {
                      self.currentOrgId=single_Orgid;
                    }
                    jQuery("#select_org").html("选择单位");
                    jQuery("#select_org").removeClass('select-active');
                    self.selectOptionOrg = 0;
                }
                self.getAssetsInfo();
            },
        },
        on: {
            pageInit: function (e, page) {
                var self = this;
                var $ = self.$;
                

                if (userInfor.isMuilUnitUser == 0){//单
                    self.currentOrgId = userInfor.organizationIds;
                    $("#select_org").hide();
                } else {//多
                    if (single_Orgid == "") {
                      self.currentOrgId=userInfor.organizationIds;
                    } else {
                      self.currentOrgId=single_Orgid;
                    }
                    jQuery("#select_org").show().click(function(e) {
                        loadSelectUnitFunc(function(data){
                            //选中
                            if(self.selectOptionOrg != data.orgId){
                                self.selectOptionOrg = data.orgId;
                                self.currentOrgId=data.orgId;
                                jQuery("#select_org").html(data.orgName);
                                jQuery("#select_org").addClass('select-active');
                            } else {
                                self.selectOptionOrg = 0;
                                if (single_Orgid == "") {
                                  self.currentOrgId=userInfor.organizationIds;
                                } else {
                                  self.currentOrgId=single_Orgid;
                                }
                                jQuery("#select_org").html("选择单位");
                                jQuery("#select_org").removeClass('select-active');
                            }
                            self.getAssetsInfo();
                        },false,self.selectOptionOrg);
                    });
                }
                //搜索
            },
            pageBeforeIn:function(e,page) {
                var self = this;
                //重现筛选条件
                if(localStorage.getItem("ilink_select_option")){
                    var selectHistory = JSON.parse(localStorage.getItem("ilink_select_option"));
                    if(selectHistory.page == "assetsListForMore"){
                        self.currentOrgId = selectHistory.organizationIds;
                        jQuery("#select_org").html(selectHistory.orgName).addClass('select-active');
                    }
                }
                self.getAssetsInfo();
            },
            pageBeforeOut: function(e, page) {
                var self = this;
                if(self.currentOrgId != userInfor.organizationIds){
                    let params = {
                        page:'assetsListForMore',
                        organizationIds:self.currentOrgId,
                        orgName:jQuery("#select_org").html(),
                    }
                    saveSelectOption(params);
                }
            }
        }
    }
</script>
<style scoped>
    .unitStat-list-dslist ul:before{
        height: 0 !important;
    }
    .select-option {
        padding: 10px 5px;
        font-size: 12px;
        z-index: 3;
        position: fixed;
        width: 100%;
        margin-top: 48px;
    }
   .moreDectorState-page .unitStat-list-dslist{
        padding-top: 25px;
   }
    .global-search {
        background: #fff;
        height: 48px;
        color: #666666 !important;
        font-size: 12px;
        text-align: center;
        line-height: 48px;
    }
    .global-search i {
        font-size: 15px;
        line-height: 48px;
        overflow: hidden;
    }
    .item-title span {
        text-overflow: ellipsis;
        white-space: nowrap;
        overflow: hidden;
        font-size: 12px;
    }
    .decter-name{
        font-size: 16px !important;
    }
    .item-inner div{
        line-height: 25px; 
    }
    .assets-status span{
        color: #2471CA;
        padding-right: 10px;
    }
</style>